<?php
    require "conn.php";
    mysqli_query($conn,"set names utf8");

    $name=$_GET["n"];
    $logo=$_GET["i"];
    $txt=$_GET["t"];
    $ip= $_SERVER['REMOTE_ADDR'];
    $time = date("Y-m-d");
    
    
    // 计算中文字符串长度
    function utf8_strlen($string = null) {
        // 将字符串分解为单元
        preg_match_all("/./us", $string, $match);
        // 返回单元个数
        return count($match[0]);
    }
    
    
    if( utf8_strlen($txt) > 200){
        echo("留言要素过多，建议精炼为200字内");
        exit();
    }
  
      
     
    if(!ctype_space($txt) && !empty($txt) && !ctype_space($nane) && !empty($name)){
        if(ctype_space($logo) || empty($logo)){
            $logo = "auto";
        }
        $sql = "INSERT INTO liuyan (name,logo,txt,ip,time) VALUE ('$name','$logo','$txt','$ip','$time')";
        $result = mysqli_query($conn,$sql);
        if(!$result){       
            echo $result;
		    echo "留言不成功<br/>";
	    }else{
		    echo "留言成功";
	    }
    }else{
        echo "请检查是否输入了朋友的名字或对朋友说的话";
        exit();
    }
?>